{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c4697ad7",
   "metadata": {},
   "source": [
    "---------------\n",
    "* 日期: 2022-10-19\\week10\n",
    "* 课程： python\n",
    "* 记录人：姚远航\n",
    "---------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "1abd352b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入余额：100\n",
      "---------商品列表---------\n",
      "商品序号: 0 蜜雪柠檬水 4元\n",
      "商品序号: 1 蜜桃四季春 8元\n",
      "商品序号: 2 棒打鲜橙 10元\n",
      "商品序号: 3 芝士红茶 12元\n",
      "请输入商品序号：3\n",
      "商品购买成功，正在制作中...您的余额还有88元\n",
      "---------商品列表---------\n",
      "商品序号: 0 蜜雪柠檬水 4元\n",
      "商品序号: 1 蜜桃四季春 8元\n",
      "商品序号: 2 棒打鲜橙 10元\n",
      "商品序号: 3 芝士红茶 12元\n",
      "请输入商品序号：q\n",
      "您已购买的商品： [['芝士红茶', 12]]\n",
      "您的余额还有88,欢迎下次光临~~\n"
     ]
    }
   ],
   "source": [
    "# 1. 运行程序后，让用户输入支付宝余额√，然后打印我们的商品列表给用户√\n",
    "product_list = [\n",
    "    [\"蜜雪柠檬水\",4],\n",
    "    [\"蜜桃四季春\",8],\n",
    "    [\"棒打鲜橙\",10],\n",
    "    [\"芝士红茶\",12]\n",
    "]\n",
    "shopping_car =[]\n",
    "\n",
    "Alipay = int(input(\"请输入余额：\"))\n",
    "\n",
    "while True:\n",
    "    print(\"---------商品列表---------\")\n",
    "    for i in range(4):\n",
    "        print(\"商品序号:\",i,product_list[i][0],str(product_list[i][1])+\"元\")   # 格式化输出\n",
    "    # 2. 让用户输入商品编号进行商品的购买 ：直接用商品列表的 index 作为商品标号\n",
    "    user_choice = input(\"请输入商品序号：\")\n",
    "    # 情景1：用户正在购买，输入商品编号\n",
    "    if user_choice.isdigit():\n",
    "        # 情景一：余额大于商品价格\n",
    "        if Alipay >= product_list[int(user_choice)][1]:\n",
    "            Alipay = Alipay - product_list[int(user_choice)][1]\n",
    "            shopping_car.append(product_list[int(user_choice)])\n",
    "            print(\"商品购买成功，正在制作中...您的余额还有%s元\"%(Alipay))\n",
    "        # 情景二：余额小于商品价格\n",
    "        else:\n",
    "            print(\"您的余额不足，请更换支付方式~~~\")\n",
    "    # 情景2：用户输入退出，结束购买\n",
    "    elif user_choice == \"q\":\n",
    "        print(\"您已购买的商品：\",shopping_car)\n",
    "        print(\"您的余额还有%s,欢迎下次光临~~\"%(Alipay))\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "54a35ecc",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eb9b4804",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "074d3d1b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cc25e7ea",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
